package com.neusoft.carsale.controller;
import java.util.List;

import org.apache.log4j.Logger;

/**
 * 
 * @author Administrator
 *
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.neusoft.carsale.bean.Client;
import com.neusoft.carsale.bean.Client;
import com.neusoft.carsale.bean.Pager;
import com.neusoft.carsale.bean.Result;
import com.neusoft.carsale.bean.Store;
import com.neusoft.carsale.service.ClientService;
import com.neusoft.carsale.service.ClientService;
import com.neusoft.carsale.service.StoreService;

@Controller
@RequestMapping("client")
public class ClientController {
	Logger logger = Logger.getLogger(ClientController.class);
	@Autowired
	private ClientService clientService;


	@RequestMapping("list")
	@ResponseBody
	public Pager<Client> list(Client client, @RequestParam(defaultValue = "1", value = "page") Integer page,
			@RequestParam(defaultValue = "10", value = "rows") Integer rows) {
		logger.info(client);
		Pager<Client> pager = new Pager<Client>(page, rows);
		pager.setCondition(client);
		List<Client> list = clientService.findList(pager);
		int total = clientService.findTotal(pager);
		pager.setRows(list);
		pager.setTotal(total);
		return pager;

	}

	@RequestMapping("add")
	@ResponseBody
	public Result add(Client client) {
		Result result = new Result(Boolean.FALSE, "添加失败");
		boolean ret = clientService.add(client);
		if (ret) {
			result = new Result(Boolean.TRUE, "添加成功");
		}
		return result;

	}

	@RequestMapping("edit")
	@ResponseBody
	public Result edit(Client client) {
		Result result = new Result(Boolean.FALSE, "修改失败");
		boolean ret = clientService.edit(client);
		if (ret) {
			result = new Result(Boolean.TRUE, "修改成功");
		}
		return result;

	}

	@RequestMapping("delete")
	@ResponseBody
	public Result delete(Client client) {
		Result result = new Result(Boolean.FALSE, "删除失败");
		boolean ret = clientService.delete(client);
		if (ret) {
			result = new Result(Boolean.TRUE, "删除成功");
		}
		return result;

	}

	

}

